﻿Imports System.Data.SqlClient
Public Class frm_TheHocVien

    Private Sub cmd_HienThi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_HienThi.Click
        If txt_MaHocVien.Text = "" Then
            MsgBox("Vui lòng nhập mã học viên vào")
            Exit Sub
        Else
            Dim cmd1 As New SqlCommand("sp_ktTheHocVien", conn)
            cmd1.CommandType = CommandType.StoredProcedure
            cmd1.Parameters.AddWithValue("@MaHV", Trim(txt_MaHocVien.Text))
            Dim i As Integer = cmd1.ExecuteScalar
            If i = 0 Then
                MsgBox("Mã học viên không tồn tại")
                Exit Sub
            End If
        End If
        Dim cmd As New SqlCommand("sp_TheHocVien", conn)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@MaHV", Trim(txt_MaHocVien.Text))
        Dim da As New SqlDataAdapter(cmd)

        Dim ds As New DataSet
        da.Fill(ds, "sp_TheHocVien")

        Dim cr As New crystalreports_thehocvien
        cr.SetDataSource(ds.Tables("sp_TheHocVien"))
        crv_TheHocVien.ReportSource = cr
        crv_TheHocVien.Refresh()
        
    End Sub

    Private Sub frm_TheHocVien_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        crv_TheHocVien.Width = Me.Width - 20
        crv_TheHocVien.Height = Me.Height - crv_TheHocVien.Top - 20
    End Sub

    Private Sub frm_TheHocVien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn.Open()
    End Sub
End Class